﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace Movies
{
    public partial class FormDefineMovieLocation : Form
    {
        public FormDefineMovieLocation()
        {
            InitializeComponent();
        }

        private void movieDefRemove_Click(object sender, EventArgs e)
        {
            try
            {
                int sel = folderList.SelectedIndex;
                folderList.Items.RemoveAt(sel);

            }catch(SystemException ex)
            {
                HelperContentProvider.OmitWarning(ex);
            }
            updateMovieFolder();

        }

        private void movieDefAdd_Click(object sender, EventArgs e)
        {
            selectFolder.ShowDialog();
            String selectedPath = selectFolder.SelectedPath;
            if (selectedPath != "")
            {
                if (folderList.Items.Contains("------ Add Folders ------"))
                {
                    folderList.Items.Clear();
                }
                folderList.Items.Add(selectedPath);   
            }
            updateMovieFolder();

        }

        private void updateMovieFolder()
        {
            IEnumerator folders = folderList.Items.GetEnumerator();
            HelperDataProvider.getDataStore().updateMoviesFolder(folders);
        }

        private void movieDefOk_Click(object sender, EventArgs e)
        {
            
            Form movieList = new FormDisplayMoviesInList();
            movieList.MdiParent = Movies.FormMainWindow.ActiveForm;
            movieList.Show();

        }

        private void downloadDetailsButton_Click(object sender, EventArgs e)
        {
            WinDisplayControllor.ShowDetailsDownloadWin();
            
        }

        private void MovieDef_Load(object sender, EventArgs e)
        {
            List<String> folders =  HelperDataProvider.getDataStore().getMoviesFolder();
            if(folders==null){
                return;
            }
            foreach (String folder in folders)
            {
                String readfolder = folder.Trim();
                if (folderList.Items.Contains("------ Add Folders ------"))
                {
                    folderList.Items.Clear();
                }
                folderList.Items.Add(folder);
             }
        }

        private void doneButton_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void MovieDef_FormClosed(object sender, FormClosedEventArgs e)
        {
            WinDisplayControllor.ApplyChangesOnLoadedWin();
        }
    }
}
